

***GENERATE SIMPLE MEAN STATISTICS	
clear

use "$workingnew/decomposition_SS_ProdR_new_kl_ad_robust"
	
	xtset co_code1 year
	
	gen diff_ln_IND = ln_IND - L.ln_IND
	gen diff_ln_IVS = ln_IVS - L.ln_IVS
	gen diff_tfpr = tfpr - L.tfpr
	
	foreach var in wIPT_IND_CHN wIPT_LMI_CHN_EXCL_IND rwIPT_IND_CHN rwIPT_LMI_CHN_EXCL_IND {
		generate ln_`var' = ln(`var')
		generate diff_`var' = ln_`var' - L.ln_`var'
	}

	foreach v in diff_tfpr diff_ln_IVS {
		drop if missing(`v')
	}
		
	destring(nic_08_2dig), g(nic2)
	ivreghdfe drop_term (diff_ln_IND diff_wIPT_IND_CHN = diff_ln_IVS diff_wIPT_LMI_CHN_EXCL_IND ) , a(nic2#year) first cluster(nic_08_4dig)
			generate sample0 = e(sample)
			keep if sample0 == 1
			
generate constant = 1

label var constant "Mean"

***MEANS OF ADDING TERMS AND DROPPING TERMS HAVE THE RIGHT SIGN
reg adding_term constant, cluster(co_code1) noc
eststo Adding1, title("Adding Baseline")
reg adding_term_h_j constant, cluster(co_code1) noc
eststo Adding2, title("Adding Alternative") 
reg adding_term_a_j constant, cluster(co_code1) noc
eststo Adding3, title("Adding TFPQ")
reg adding_term_d_j constant, cluster(co_code1) noc
eststo Adding4, title("Adding Demand")

reg drop_term constant, cluster(co_code1) noc
eststo Dropping1, title("Dropping Baseline")
reg drop_term_h_j constant, cluster(co_code1) noc
eststo Dropping2, title("Dropping Alternative")
reg drop_term_a_j constant, cluster(co_code1) noc
eststo Dropping3, title("Dropping TFPQ")
reg drop_term_d_j constant, cluster(co_code1) noc
eststo Dropping4, title("Dropping Demand")


esttab Adding1 Adding2 Adding3 Adding4 Dropping1 Dropping2 Dropping3 Dropping4 using "$tables/SumAddDrop.tex" , cells(b(nostar fmt(%9.3f)) se(par fmt(%9.3f))) nodepvars ///
eqlabels(none) mlabels("/makecell{Add // Base}" "/makecell{Add // MP}" "/makecell{Add // TFPQ}" "/makecell{Add // Demand}" "/makecell{Drop // Base}" "/makecell{Drop // MP}" "/makecell{Drop // TFPQ}" "/makecell{Drop // Demand}") keep(constant) label ///
 collabels(none) replace  
 
 
